<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');

/**
 * TYPOlight webCMS
 *
 * The TYPOlight webCMS is an accessible web content management system that 
 * specializes in accessibility and generates W3C-compliant HTML code. It 
 * provides a wide range of functionality to develop professional websites 
 * including a built-in search engine, form generator, file and user manager, 
 * CSS engine, multi-language support and many more. For more information and 
 * additional TYPOlight applications like the TYPOlight MVC Framework please 
 * visit the project website http://www.typolight.org.
 *
 * This is the data container array for table tl_taxonomy.
 *
 * PHP version 5
 * @copyright  Martin Komara 2007 
 * @author     Martin Komara 
 * @package    Taxonomy 
 * @license    GPL 
 * @filesource
 */


/**
 * Table tl_taxonomy 
 */
$GLOBALS['TL_DCA']['tl_custommenu'] = array
(

    // Config
    'config' => array
    (
        'dataContainer'               => 'Table',
        'enableVersioning'            => true,
        'label'                       => &$GLOBALS['TL_LANG']['tl_custommenu']['title'],
    ),

    // List
    'list' => array
    (
        'sorting' => array
        (
            'mode'                    => 5,
            'fields'                  => array('title'),
            'flag'                    => 1,
            'panelLayout'             => 'search,sort,filter,limit ',
            'icon'                    => 'system/modules/custommenu/html/icon.gif',
        ),
        'label' => array
        (
            'fields'                  => array('title'),
            'format'                  => '%s'
        ),
        'global_operations' => array
        (
            'all' => array
            (
                'label'               => &$GLOBALS['TL_LANG']['MSC']['all'],
                'href'                => 'act=select',
                'class'               => 'header_edit_all',
                'attributes'          => 'onclick="Backend.getScrollOffset();"'
            )
        ),
        'operations' => array
        (
            'edit' => array
            (
                'label'               => &$GLOBALS['TL_LANG']['tl_custommenu']['edit'],
                'href'                => 'act=edit',
                'icon'                => 'edit.gif',
            ),
            'copy' => array
            (
                'label'               => &$GLOBALS['TL_LANG']['tl_custommenu']['copy'],
                'href'                => 'act=copy',
                'icon'                => 'copy.gif',
            ),
            'copyChildren' => array
            (
                'label'               => &$GLOBALS['TL_LANG']['tl_custommenu']['copyChildren'],
                'href'                => 'act=paste&amp;mode=copy&amp;childs=1',
                'icon'                => 'copychilds.gif',
                'attributes'          => 'onclick="Backend.getScrollOffset();"',
            ), 
            'delete' => array
            (
                'label'               => &$GLOBALS['TL_LANG']['tl_custommenu']['delete'],
                'href'                => 'act=delete',
                'icon'                => 'delete.gif',
                'attributes'          => 'onclick="if (!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\')) return false; Backend.getScrollOffset();"'
            ),
            'cut' => array
            (
                'label'               => &$GLOBALS['TL_LANG']['tl_custommenu']['cut'],
                'href'                => 'act=paste&amp;mode=cut',
                'icon'                => 'cut.gif',
                'attributes'          => 'onclick="Backend.getScrollOffset();"',
            ), 
            'delete' => array
            (
                'label'               => &$GLOBALS['TL_LANG']['tl_custommenu']['delete'],
                'href'                => 'act=delete',
                'icon'                => 'delete.gif',
                'attributes'          => 'onclick="if (!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\')) return false; Backend.getScrollOffset();"',
            ), 
            'show' => array
            (
                'label'               => &$GLOBALS['TL_LANG']['tl_custommenu']['show'],
                'href'                => 'act=show',
                'icon'                => 'show.gif'
            ),
        )
    ),

    // Palettes
    'palettes' => array
    (
        '__selector__'                => array('type', 'itemType', 'defineTableRoots', 'definePageRoots'),
        'default'                     => 'title,type',
        'root'                        => 'title,type',
        'item'                        => 'title,type,itemType;cssID',
        'itemnolink'                  => 'title,type,itemType;cssID',
        'iteminternal'                => 'title,type,itemType,targetId,newWindow;cssID',
        'itemexternal'                => 'title,type,itemType,targetUrl,newWindow;cssID',
        'itemhtml'                    => 'title,type,itemType,html;cssID',
        'tablegen'                    => 'title,type,tableName,tableColumn,targetId,targetParams,preserveParams,defineTableRoots,tableOrderBy,tableWhere;cssID',
        'pagegen'                     => 'title,type,definePageRoots;{nav_legend},levelOffset,showLevel,hardLimit,showProtected;',
    ),
    
    'subpalettes' => array
    (
        'defineTableRoots' => 'tableRoots,useTableRootChildren',
        'definePageRoots'  => 'pageRoots,usePageRootChildren',
    ),

    // Fields
    'fields' => array
    (
        'title' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['title'],
            'exclude'                 => true,
            'inputType'               => 'text',
            'eval'                    => array('mandatory'=>true, 'maxlength'=>128)
        ),
        
        'type' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['type'],
            'default'                 => 'item',
            'exclude'                 => true,
            'inputType'               => 'select',
            'options'                 => array('root', 'item', 'pagegen', 'tablegen'),
            'reference'               => &$GLOBALS['TL_LANG']['tl_custommenu'],
            'eval'                    => array('submitOnChange'=>true)
        ),
        
        'itemType' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['itemType'],
            'default'                 => 'internal',
            'exclude'                 => true,
            'inputType'               => 'select',
            'options'                 => array('nolink', 'internal', 'external', 'html'),
            'reference'               => &$GLOBALS['TL_LANG']['tl_custommenu'],
            'eval'                    => array('submitOnChange'=>true)
        ),
        
        'targetId' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['targetId'],
            'exclude'                 => true,
            'inputType'               => 'pageTree',
            'eval'                    => array('mandatory' => true, 'fieldType'=>'radio', 'tl_class'=>'clr')
        ),
        
        'targetUrl' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['targetUrl'],
            'exclude'                 => true,
            'inputType'               => 'text',
            'eval'                    => array('mandatory'=>true, 'maxlength'=>255)
        ),
        
        'newWindow' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['newWindow'],
            'inputType'               => 'checkbox',
        ),
        
        'html' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['html'],
            'inputType'               => 'textarea',
            'eval'                    => array('tl_class'=>'clr'),
        ),
        
        'cssID' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['cssID'],
			'exclude'                 => true,
			'inputType'               => 'text',
			'eval'                    => array('multiple'=>true, 'size'=>2)
		),
        
        'targetParams' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['targetParams'],
            'exclude'                 => true,
            'inputType'               => 'optionWizard',
        ),
        
        'preserveParams' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['preserveParams'],
            'inputType'               => 'checkbox',
        ),
        
        'tableName' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['tableName'],
            'inputType'               => 'select',
            'options_callback'        => array('tl_custommenu', 'getTables'),
            'eval'                    => array('tl_class'=>'w50', 'submitOnChange'=>true)
        ),
        
        'tableColumn' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['tableColumn'],
            'inputType'               => 'select',
            'options_callback'        => array('tl_custommenu', 'getTableFields'),
            'eval'                    => array('tl_class'=>'w50', 'submitOnChange'=>true)
        ),
        
        'defineTableRoots' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['defineTableRoots'],
            'inputType'               => 'checkbox',
            'eval'                    => array('submitOnChange'=>true)
        ),
        
        'tableRoots' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['tableRoots'],
            'inputType'               => 'tableTree',
            'eval'                    => array('fieldType' => 'checkbox', 'mandatory' => true),
            'load_callback'           => array(array('tl_custommenu', 'setSelectedTable')),
        ),
        
        'useTableRootChildren' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['useTableRootChildren'],
            'inputType'               => 'checkbox',
        ),
        
        'tableOrderBy' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['tableOrderBy'],
            'inputType'               => 'text',
        ),
        
        'tableWhere' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['tableWhere'],
            'inputType'               => 'textarea',
            'eval'                    => array('style'=>'height:60px;', 'tl_class'=>'clr', 'decodeEntities' => true),
        ),
        
        'definePageRoots' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['definePageRoots'],
            'inputType'               => 'checkbox',
            'eval'                    => array('submitOnChange'=>true)
        ),
        
        'pageRoots' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['pageRoots'],
            'inputType'               => 'pageTree',
            'eval'                    => array('mandatory' => true, 'fieldType'=>'checkbox', 'tl_class'=>'clr')
        ),
        
        'usePageRootChildren' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_custommenu']['usePageRootChildren'],
            'inputType'               => 'checkbox',
        ),
        
        'levelOffset' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_module']['levelOffset'],
			'exclude'                 => true,
			'inputType'               => 'text',
			'eval'                    => array('maxlength'=>5, 'rgxp'=>'digit', 'tl_class'=>'w50')
		),
        
		'showLevel' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_module']['showLevel'],
			'exclude'                 => true,
			'inputType'               => 'text',
			'eval'                    => array('maxlength'=>5, 'rgxp'=>'digit', 'tl_class'=>'w50')
		),
        
		'hardLimit' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_module']['hardLimit'],
			'exclude'                 => true,
			'inputType'               => 'checkbox',
			'eval'                    => array('tl_class'=>'w50')
		),
        
		'showProtected' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_module']['showProtected'],
			'exclude'                 => true,
			'inputType'               => 'checkbox',
			'eval'                    => array('tl_class'=>'w50')
		),
    )
);

class tl_custommenu extends Backend
{
    public function getTables()
    {
        return $this->Database->listTables();
    }
    
    public function getTableFields(DataContainer $dc)
    {
        $objTable = $this->Database->prepare("SELECT tableName FROM tl_custommenu WHERE id=?")
                ->limit(1)
                ->execute($dc->id);
         
        if ($objTable->numRows > 0 && $this->Database->tableExists($objTable->tableName))
        {
            $fields = $this->Database->listFields($objTable->tableName);
            return array_map(create_function('$x', 'return $x["name"];'), $fields);
        }
    }
    
    public function setSelectedTable($value, DataContainer $dc)
    {
        $objTable = $this->Database->prepare("SELECT tableName, tableColumn FROM tl_custommenu WHERE id=?")
            ->limit(1)
            ->execute($dc->id);
            
        if ($objTable->numRows)
        {
            $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['tableColumn'] =
                    $objTable->tableName.'.'.$objTable->tableColumn;
        }
        
        return $value;
    }
}

?>
